﻿CREATE PROCEDURE [dbo].[TempArticleSales_UpdateArticleCodes]
	@ArticleCodes varchar(max)
AS

Update TempArticleSales
Set ArticleCode = codes.NewCode
From TempArticleSales ts
Inner Join (
Select 
	Code = (Select SUBSTRING(Id,1,CHARINDEX(',', Id) - 1))
	, NewCode = (Select SUBSTRING(Id,CHARINDEX(',', Id) + 1,LEN(Id) + 1))
From (Select Id From dbo.SplitStrings(@ArticleCodes, ';')) 
data
) codes on ts.ArticleCode = codes.Code